package tests;

import java.util.List;

import junit.framework.TestCase;
import metier.entite.user.TypeUser;
import metier.entite.user.User;
import metier.sercurity.PasswordEncryptor;
import persistance.userDB.UserDB;

public class PersistanceTests extends TestCase{

	public void testUpdateUser(){

		// Create user
		String passwordClient = "client" ;
		String passwordAdmin = "adminadmin" ;
		User user1 = new User("user1", PasswordEncryptor.encode(passwordClient), TypeUser.CLIENT) ;
		User user2 = new User("user2", PasswordEncryptor.encode(passwordClient), TypeUser.CLIENT) ;
		User user3 = new User("user3", PasswordEncryptor.encode(passwordClient), TypeUser.CLIENT) ;

		// Create Admin
		User admin1 = new User("admin1", PasswordEncryptor.encode(passwordAdmin), TypeUser.ADMIN) ;

		try {
			// Create Table
			UserDB.createTableUser() ;

			// Add users
			UserDB.addUser(user1);
			UserDB.addUser(user2);
			UserDB.addUser(user3);
			UserDB.addUser(admin1);

			// Remove User
			UserDB.removeUser(user2) ;

			// Uodate User
			User user3Update = new User("user3", PasswordEncryptor.encode("newPAssword"), TypeUser.CLIENT) ;
			user3Update.setId(3) ;
			UserDB.updateUser(user3Update) ;

			// Get All Users
			List<User> users = UserDB.getAllUsers() ;
			for (User u : users){
				System.out.println(u.toString());
			}
			
			// Remove Users
			UserDB.removeUser(user1) ;
			UserDB.removeUser(user3Update) ;
			UserDB.removeUser(admin1) ;

		} catch (Exception e) {
			System.out.println();
		}
	}

}
